package com.eis.persist.dao.util;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;

import com.eis.persist.model.function.PersistFunctionSchema;

public class FunctionSchemaBatchPreparedStatementSetter implements BatchPreparedStatementSetter {
	private final List<PersistFunctionSchema> newSchemas;

	public FunctionSchemaBatchPreparedStatementSetter(List<PersistFunctionSchema> newSchemas) {
		this.newSchemas = newSchemas;
	}
	
	@Override
	public void setValues(PreparedStatement ps, int i) throws SQLException {
		PersistFunctionSchema newSchema = newSchemas.get(i);
		ps.setInt(1, newSchema.getFunctionDBID());
		ps.setString(2, newSchema.getFieldName());
		ps.setInt(3, newSchema.getFieldLength());
		ps.setString(4, newSchema.getFieldType());
		ps.setInt(5, newSchema.isExt() ? 1 : 0);
		ps.setString(6, newSchema.getDefaultDisplayName());
	}

	@Override
	public int getBatchSize() {
		return newSchemas.size();
	}

}
